/*
* 网易云通信SDK初始化
*/

import {nimAppKey} from '../../utils/config'
import store from '../'
import NIMSDK from 'nim-web-sdk-ng/dist/NIM_UNIAPP_SDK'


export function initNimSdk({ state, commit, dispatch }, userInfo) {
	//初始化云通信
	const nim = new NIMSDK({
	  appkey: nimAppKey,
	  account: userInfo.uid.toString(),
	  token: userInfo.nimToken,
	  debugLevel: 'debug',
	});
	
	const eventList = [
	  'logined',
	  'multiPortLogin',
	  'kicked',
	  'willReconnect',
	  'disconnect',
	  'msg',
	  'syncdone',
	  'proxyMsg', 'syncRoamingMsgs', 'syncOfflineMsgs',
	  'syncMyNameCard', 'syncdone', 'sessions', 'updateMyNameCard', 'updateBlackList', 'updateMuteList',
	  'sysMsg', 'syncSysMsgs', 'syncFriend', 'friends', 'users', 'updateSystemMessages', 'sysMsgUnread', 'pushEvents',
	  'teamMsgReceipts', 'updateSession',
	  'teams',
	  'createTeam',
	  'updateTeamMember',
	  'updateTeam', 'addTeamMembers', 'updateTeamManagers', 'transferTeam', 'removeTeamMembers', 'dismissTeam', 'updateTeamMembersMute'
	];
	
	// eventList.forEach(function (key) {
	// 	nim.on(key, function (res) {
	// 		console.log(`Receive ${key} event：`, res ? JSON.parse(JSON.stringify(res)) : res);
	// 	})
	// });
	nim.on('syncFriend', function (friend) {
	  console.log('multi client sync receive', friend)
	})
	nim.on('friends', function (friends) {
		console.log("来了 大哥")
	  console.log('initial sync receive', friends)
	})
	
	
	// then，receive event 'logined'
	nim.connect();		
	
	state.nim = nim;
}